package com.kungkhies.mvc.home;

import com.kungkhies.services.kungkher.KungkherService;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import javax.inject.Inject;
import org.springframework.beans.factory.annotation.Autowired;

@Controller
public class HomeController
{
    private KungkherService kungkherService;

    @Autowired
    public HomeController(KungkherService kungkherService)
    {
        this.kungkherService = kungkherService;
    }

    @RequestMapping(value =
    {
        "/", "/home"
    }, method = RequestMethod.GET)
    public String showHomePage(Map<String, Object> model)
    {
        System.out.println("HomeController: SHOWHOMEPAGE METHOD");

        if (kungkherService == null)
        {
            System.out.println("kungkherService is NULL in HomeController constructor");
        }
        else
        {
            System.out.println("kungkherService is NOT NULL in HomeController constructor");
        }

//        if (kungkherService.getRecentKungkhies(5) == null)
//        {
//            System.out.println("kungkhieService.getRecentKungkhies(5) is null in HomeController constructor");
//        }
//        else
//        {
//            System.out.println("kungkhieService.getRecentKungkhies(5) is NOT null in HomeController constructor");
//
//            System.out.println("kungkhieService.getRecentKungkhies(5).size(): " + kungkherService.getRecentKungkhies(5).size());
//        }



//        model.put("kungkhies", kungkherService.getRecentKungkhies(5));
        return "home";
    }
    //<start id="spittlesPerPage"/> 
    public static final int DEFAULT_KUNGKHIES_PER_PAGE = 25;
    private int kungkhiesPerPage = DEFAULT_KUNGKHIES_PER_PAGE;

    public void setKungkhiesPerPage(int kungkhiesPerPage)
    {
        this.kungkhiesPerPage = kungkhiesPerPage;
    }

    public int getKungkhiesPerPage()
    {
        return kungkhiesPerPage;
    }
    //<end id="spittlesPerPage"/> 
}
